package it.patterns.creational.prototype;

public class Client {

	private static Prototype calculateEnd(Prototype start, int hours) {
		int hr = start.getHours() + hours;
		hr = hr < 24 ? hr : hr - 24;
		Prototype endTime = start.cloneItself();
		endTime.setTime(hr, start.getMinutes(), start.getSeconds());
		return endTime;
	}

	public static void doPrototype() {

		Prototype t1 = new ConcretePrototypeA();
		t1.setTime(15, 20, 10);
		Prototype tEnd1 = calculateEnd(t1, 6);
		System.out.println("Start: " + t1.getHours() + ":" + t1.getMinutes()
				+ ":" + t1.getSeconds());
		System.out.println("End: " + tEnd1.getHours() + ":"
				+ tEnd1.getMinutes() + ":" + tEnd1.getSeconds());

		Prototype t2 = new ConcretePrototypeB();
		t2.setTime(10, 15, 35);
		Prototype tEnd2 = calculateEnd(t2, 6);
		System.out.println("Start: " + t2.getHours() + ":" + t2.getMinutes()
				+ ":" + t2.getSeconds());
		System.out.println("End: " + tEnd2.getHours() + ":"
				+ tEnd2.getMinutes() + ":" + tEnd2.getSeconds());
	}

}
